/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mrez.zBox.appsmodel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Ahmed
 */
public final class AppsModel {
    public static File[] m_AppsList;
    
    public AppsModel()
    {
        m_AppsList = new File[0];
        LoadAppsFromFile();
        
    }
    
    public void LoadAppsFromFile()
    {
        File settingsFile = new File("Apps.dat");
        if(!settingsFile.exists()) {
            try {
                settingsFile.createNewFile();                
            } catch (IOException ex) {
                Logger.getLogger(AppsModel.class.getName()).log(Level.SEVERE, null, ex);                
            }
            return;
        } 
        // Deserialize the settings file
        try {
            ObjectInputStream in = null;
            in = new ObjectInputStream(new FileInputStream("Apps.dat"));
            AppsModel.m_AppsList = (File[]) in.readObject();
            in.close();
        } catch (IOException | ClassNotFoundException ex) {
        }        
    }
    
    public void SaveAppsToFile()
    {
        File settingsFile = new File("Apps.dat");
        if(!settingsFile.exists()) {
            try {
                settingsFile.createNewFile();                
            } catch (IOException ex) {
                Logger.getLogger(AppsModel.class.getName()).log(Level.SEVERE, null, ex);                
            }
        } 
        // Deserialize the settings file
        try {
            ObjectOutputStream out = null;
            out = new ObjectOutputStream(new FileOutputStream("Apps.dat"));
            out.writeObject(AppsModel.m_AppsList);            
            out.close();
        } catch (IOException ex) {
        }        
    }
}
